Micron Document




Unix domain socket
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top
A Unix domain socket (UDS), local socket, or inter-process communication (IPC) socket is a communication endpoint for exchanging data between processes executing in the same Unix or Unix-like operating system.

The name Unix domain socket refers to the domain argument value AF_UNIX that is passed to the function that creates a socket system resource. The same communication domain is also selected by AF_LOCAL. cite-ref-man-unix-sockets-1-0[1]

Valid type argument values for a UDS are:cite-ref-man-unix-sockets-1-1[1]

SOCK_STREAM (compare to TCP) – for a stream-oriented socket
SOCK_DGRAM (compare to UDP) – for a datagram-oriented socket that preserves message boundaries (as on most UNIX implementations, UNIX domain datagram sockets are always reliable and don't reorder datagrams)
SOCK_SEQPACKET (compare to SCTP) – for a sequenced-packet socket that is connection-oriented, preserves message boundaries, and delivers messages in the order that they were sent

The UDS facility is a standard component of a POSIX operating system.

The API for a UDS is similar to that of an Internet socket, but rather than using an underlying network protocol, all communication occurs entirely within the operating system kernel. A UDS may use the file system as its address name space. Some operating systems, like Linux, offer additional namespaces. Processes reference a UDS as a file system inode, so two processes can communicate by opening the same socket.

In addition to sending data, processes may send file descriptors across a UDS connection using the sendmsg() and recvmsg() system calls. This allows the sending processes to grant the receiving process access to a file descriptor for which the receiving process otherwise does not have access.cite-ref-neohapsis-2-0[2]cite-ref-linux-cmsg-man-page-3-0[3] This can be used to implement a rudimentary form of capability-based security.cite-ref-wheeler-secure-linux-howto-4-0[4]

Contents


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

See also

Network socket – Software-based endpoint of network communications
Berkeley sockets – Inter-process communication API
Pipeline (Unix) – Mechanism for inter-process communication using message passing
Netlink – Linux kernel interface for inter-process communication between processes

References

cite-note-man-unix-sockets-11. "Linux Programmer's Manual (unix - sockets for local interprocess communication)". 30 April 2018. Retrieved 22 February 2019.
cite-note-neohapsis-22. "Archive of the "Postfix Discussions" mailing list". 30 September 2000. Archived from the original on 18 May 2013. Retrieved 29 September 2014.
cite-note-linux-cmsg-man-page-33. "Linux man page - cmsg(3): access ancillary data". Retrieved 9 October 2018.
cite-note-wheeler-secure-linux-howto-44. ""Secure Programming for Linux and Unix HOWTO", Section 3.4 "Sockets and Network Connections"". dwheeler.com. David A. Wheeler. 22 August 2004. Retrieved 29 September 2014.

External links

socket – System Interfaces Reference, The Single UNIX Specification, Version 5 from The Open Group
socketpair – System Interfaces Reference, The Single UNIX Specification, Version 5 from The Open Group
sendmsg – System Interfaces Reference, The Single UNIX Specification, Version 5 from The Open Group
recvmsg – System Interfaces Reference, The Single UNIX Specification, Version 5 from The Open Group
cmsg(3)Linux Programmer's Manual – Library Functions
• ucspi-unix, UNIX-domain socket client-server command-line tools
• Unix sockets vs Internet sockets
• Unix Sockets - Beej's Guide to Unix IPC